// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()

exports.main = async (event, context) => {
  const { openid } = event
  if (!openid) {
    return { code: 1, msg: '缺少openid' }
  }
  try {
    // 查询本人扔出的瓶子
    const throwRes = await db.collection('bottles').where({ openid }).get()
    // 这里暂不考虑"捡到的瓶子"，如需扩展可在bottle表加字段
    return { code: 0, myBottles: throwRes.data }
  } catch (e) {
    return { code: 2, msg: '数据库查询失败', error: e }
  }
} 